import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = (data, details) => {
    const requiredFields = [];
    if(!data || !data.brandId)
        requiredFields.push(
            formatMessage({
                id: 'validator.brandId',
                defaultMessage: '品牌'
            })
        );
    if(!data || !data.caseType)
        requiredFields.push(
            formatMessage({
                id: 'validator.caseType',
                defaultMessage: '案例类型'
            })
        );
    if(!data || !data.consultType)
        requiredFields.push(
            formatMessage({
                id: 'validator.consultType',
                defaultMessage: '咨询类型'
            })
        );
    if(!data || !data.faultCode)
        requiredFields.push(
            formatMessage({
                id: 'validator.faultCode',
                defaultMessage: '故障编号'
            })
        );
    if(!data || !data.caseTitle)
        requiredFields.push(
            formatMessage({
                id: 'validator.caseTitle',
                defaultMessage: '案例标题'
            })
        );
    if(!data || !data.caseDescription)
        requiredFields.push(
            formatMessage({
                id: 'validator.caseDescription',
                defaultMessage: '案例描述'
            })
        );
    if(!data || !data.caseAnalysis)
        requiredFields.push(
            formatMessage({
                id: 'validator.caseAnalysis',
                defaultMessage: '案例分析'
            })
        );
    if(!data || !data.solution)
        requiredFields.push(
            formatMessage({
                id: 'validator.solution',
                defaultMessage: '解决方案'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    if(!details || (details && details.length === 0)) {
        message.warning(formatMessage({
            id: 'validator.message.detail',
            defaultMessage: '车型清单不能为空！'
        }));
        return false;
    }
    if(!data || !data.attachments) {
        message.warning(formatMessage({
            id: 'validator.message.attachments',
            defaultMessage: '附件不可为空'
        }));
        return false;
    }
    return true;
};

export const newOrApproveOrderValidator = data => {
    const requiredFields = [];
    if(!data || !data.approveComment)
        requiredFields.push(
            formatMessage({
                id: 'validator.approveComment',
                defaultMessage: '审核意见'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    return true;
};
